package spzx.service.impl;

import com.atguigu.spzx.model.dto.order.OrderStatisticsDto;
import com.atguigu.spzx.model.entity.order.OrderStatistics;
import com.atguigu.spzx.model.vo.order.OrderStatisticsVo;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import spzx.mapper.OrderInfoMapper;
import spzx.service.OrderInfoService;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class OrderInfoServiceImpl implements OrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Override
    public OrderStatisticsVo getOrderStatisticsVo(OrderStatisticsDto orderStatisticsDto) {
        List<OrderStatistics> list = orderInfoMapper.selectOrderStatistics(orderStatisticsDto);

        List<String> dateList = list.stream().map(item -> {
            Date orderDate = item.getOrderDate();
            return new DateTime(orderDate).toString("yyyy-MM-dd");
        }).collect(Collectors.toList());

        List<BigDecimal> amountList = list.stream().map(item -> {
            return item.getTotalAmount();
        }).collect(Collectors.toList());

        OrderStatisticsVo orderStatisticsVo = new OrderStatisticsVo();
        orderStatisticsVo.setDateList(dateList);
        orderStatisticsVo.setAmountList(amountList);

        return orderStatisticsVo;
    }
}
